package com.itqf.Service.Topic.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.Dao.ApplystageMapper;
import com.itqf.Dao.SubjectMapper;
import com.itqf.Dao.TopicMapper;
import com.itqf.Service.Topic.TopicService;
import com.itqf.entity.Applystage;
import com.itqf.entity.Subject;
import com.itqf.entity.Topic;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TopicServiceimpl implements TopicService{
    @Resource
    private SubjectMapper subjectMapper;
    @Resource
    private ApplystageMapper applystageMapper;
    @Resource
    private TopicMapper topicMapper;

    @Override
    public List<Topic> findtopic(int subjectId) {
        Map map=new HashMap();
        map.put("subjectId",subjectId);
        return topicMapper.findtopic(map);
    }

    @Override
    public List<Subject> findsubjects(int gardeId)
    {

        if(gardeId==-1)
        {
            List<Subject> subjectList = subjectMapper.findall();
            return subjectList;
        }
        else {
            Map map = new HashMap();
            map.put("gardeId", gardeId);
            Applystage applystage = applystageMapper.findsubjecteds(map);
            List<Subject> subjectLists = applystage.getSubjectLists();
            return subjectLists;
        }
    }

    @Override
    public PageInfo<Topic> findbysearchname(int pageindex, Integer pagesize, String searchname) {
        PageHelper.startPage(pageindex,pagesize);
        Map map=new HashMap();
        map.put("searchname",searchname);
        List<Topic> topicList=topicMapper.findallbysearchname(map);
        PageInfo<Topic> pageInfo=new PageInfo<>(topicList);
        return pageInfo;
    }

    @Override
    public List<Topic> findtopics() {
       List<Topic> list=topicMapper.findtopics();
       return list;
    }

    @Override
    public PageInfo<Topic> findchuzhongtops(int pageindex, Integer pagesize) {
        PageHelper.startPage(pageindex,pagesize);
        List<Topic> list=topicMapper.findchuzhongtops();
        PageInfo<Topic> pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public Topic getTopicbytopid(int topicId) {
        Topic topic = topicMapper.selectByPrimaryKey(topicId);
        return topic;
    }

    @Override
    public Topic findtopbytopicid(int topicId) {
       return topicMapper.selectByPrimaryKey(topicId);
    }

}
